<?php
namespace app\exam\controller;

use app\exam\model\SubjectModel;
class Subject extends Common
{
    /*
        获取考题信息
        params:
            token 用户token
            index 获取考题的下标 默认从1开始
    */
    public function getSubjectInfo()
    {
        if($this->_method != 'post'){
            $res = array(
                'code' => '0001'
            );
            $this->_response($res);
        }

        $this->_checkToken();

        $params = array();
        $params['subject_index'] = $this->args['index'];

        if(is_numeric($params['subject_index']) == false || $params['subject_index'] < 1){
            $res = array(
                'code' => '0002'
            );
            $this->_response($res);
        }

        $SubjectModel = new SubjectModel();
        $ret = $SubjectModel->getSubjectInfo($this->args['token'], $params['subject_index']);

        if($ret === false){
            $res = array(
                'code' => '0003'
            );
        }elseif(empty($ret['code']) == false){
            $res = $ret;
        }else{
            $res = array(
                'code' => '0',
                'data' => $ret
            );
        }

        $this->_response($res);
    }
}
